package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.service.BaseManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class SkuManageController {
    @Autowired
    private BaseManageService baseManageService;
    /**
     * 保存SkuInfo  简称大保存  保存一个sku所有信息
     * @param skuInfo
     * @return
     */
    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        baseManageService.saveSkuInfo(skuInfo);
        return  Result.ok();
    }

    // /admin/product/list/{page}/{limit}
    /**
     * sku分页
     */
    @GetMapping("/list/{page}/{limit}")
    public Result list(@PathVariable Long page,
                       @PathVariable Long limit){
        Page<SkuInfo> skuInfoPage=new Page(page,limit);
         IPage iPage=baseManageService.getList(skuInfoPage);
         return  Result.ok(iPage);
    }
    //  /admin/product/onSale/{skuId}   上架
    @GetMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId){
        baseManageService.onSale(skuId);
        return Result.ok();
    }
    //  /admin/product/cancelSale/{skuId}   下架
    @GetMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId){
        baseManageService.cancelSale(skuId);
        return Result.ok();
    }
}
